#ifndef PETMANAGE_H
#define PETMANAGE_H

#include <QMainWindow>
#include <QTreeWidget>
#include <QTableWidget>
#include "sqlconn.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class PetManage; }
QT_END_NAMESPACE

template <class T1>
void setInfosToInfoTable(QTableWidget* table, T1 infos) {
    for (int i= 0;i<infos.size();i++) {
        QStringList info = infos[i].getInfo();
        for (int j=0;j<info.size();j++) {
            QTableWidgetItem * item = new QTableWidgetItem();
            item->setText(info[j]);
            item->setTextAlignment(Qt::AlignRight | Qt::AlignCenter);
            table->setItem(i,j,item);
        }
    }
    table->setEditTriggers ( QAbstractItemView::NoEditTriggers );
}

template <class T1>
void setInfosToManTable(QTableWidget* table, T1 infos) {
    for (int i= 0;i<infos.size();i++) {
        QStringList info = infos[i].getInfo();
        for (int j=0;j<info.size();j++) {
            QTableWidgetItem *item1 =new QTableWidgetItem();
            item1->setText(info[j]);
            item1->setTextAlignment(Qt::AlignRight | Qt::AlignCenter);
            if (j==0)
            {
                item1->setFlags(item1->flags() & (~Qt::ItemIsEditable));
            }
            table->setItem(i,j,item1);
        }
        QTableWidgetItem *item = new QTableWidgetItem();
        item->setIcon(QIcon(":img/delete.png"));
        item->setFlags(item->flags() & (~Qt::ItemIsEditable));
        table->setItem(i,info.size(),item);
    }
//    table->insertRow(infos.size());
}

class PetManage : public QMainWindow
{
    Q_OBJECT

public:
    PetManage(QWidget *parent = nullptr);
    ~PetManage();
    void setDocInfoTable();
    void setGueInfoTable();
    void setPetInfoTable();
    void setDocManTable();
    void setGueManTable();
    void setPetManTable();
    void setTreeWidget();

private slots:
    void on_treeWidget_itemClicked(QTreeWidgetItem *item, int column);
    void on_deleteDoc(QTableWidgetItem*);
    void on_updateDoc(int, int);
    void on_deleteGue(QTableWidgetItem*);
    void on_updateGue(int, int);
    void on_deletePet(QTableWidgetItem*);
    void on_updatePet(int, int);
    void change_doc();

    void on_add_gue_clicked();

    void on_add_doc_clicked();

    void on_add_pet_clicked();

private:
    Ui::PetManage *ui;

    QList<Doctor> doctors;
    QList<Guest> guests;
    QList<Pet> pets;
    SQLConn* sql;
    QTableWidget *doctorInfo;
    QTableWidget *guestInfo;
    QTableWidget *petInfo;
    QTableWidget *doctorMan;
    QTableWidget *guestMan;
    QTableWidget *petMan;
};
#endif // PETMANAGE_H
